window.onload = function () {
    document.getElementById("administrative").className = "add-nav-active";
    document.getElementById("document").className = "add_class";
    document.getElementById("organizational_management_ul").style.display = "inline-block";
    document.getElementById("jiantou").className = "iconfont icon-jiantou-xia";
};



function click_ul() {
    if (document.getElementById("jiantou").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou").className = "iconfont icon-jiantou-xia";
        document.getElementById("organizational_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou").className = "iconfont icon-jiantou-shang";
        document.getElementById("organizational_management_ul").style.display = "none";
    }
}

function click_ul1() {
    if (document.getElementById("jiantou1").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-xia";
        document.getElementById("gebruikersrol_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-shang";
        document.getElementById("gebruikersrol_ul").style.display = "none";
    }
}

function click_ul2() {
    if (document.getElementById("jiantou2").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-xia";
        document.getElementById("meeting_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-shang";
        document.getElementById("meeting_management_ul").style.display = "none";
    }
}

function click_ul3() {
    if (document.getElementById("jiantou3").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-xia";
        document.getElementById("issue_approval_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-shang";
        document.getElementById("issue_approval_ul").style.display = "none";
    }
}

// 更改发文字号
function get_option() {
    var myselect = document.getElementById("number_type");
    var index = myselect.selectedIndex;　　　　　　　　　//获取被选中的索引
    var number_type = myselect.options[index].value;　　　　　　//获取被选中的值
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/document.html", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send("number_type="+String(number_type));
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                document.getElementById("dispatch-size").innerHTML = JsonDate["data"][0]["serial_definition"];
            }
        }
    };
}



// 选择流程执行人弹框
function entrust() {
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/technological/delegation", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                var JsonDate = JSON.parse(xhr.responseText);
                console.log(JsonDate);
                window.personnel_list = JsonDate["data"];
                var department_list = document.getElementById("department_list");
                department_list.innerHTML = "";
                var ul_tag = document.createElement("ul");
                for (var i=0; i<JsonDate["branch_list"].length; i++) {
                    var li_tag = document.createElement("li");
                    li_tag.innerHTML = JsonDate["branch_list"][i];li_tag.setAttribute("onclick", "choice_peopel('"+JsonDate["branch_list"][i]+"')");li_tag.className="li-class";
                    ul_tag.appendChild(li_tag);
                    department_list.appendChild(ul_tag);
                }
            }
        }
    };
}



// 创建右侧选择人员列表
function choice_peopel(choice_key) {
    var personnel_list = window.personnel_list;
    document.getElementById("img-display1").style.display = "none";
    var t_table = document.getElementById("t_table2");
    deltr1();
    for (var i=0; i<personnel_list[choice_key].length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");
        td.innerHTML = "<input id='"+personnel_list[choice_key][i]+"' class='check_box' type=\"checkbox\" onclick='choice_consignor(this.id)'>";td.style.textAlign = "center";
        td1.innerHTML = i+1;td1.style.textAlign = "center";
        td2.innerHTML = personnel_list[choice_key][i];td2.title =personnel_list[choice_key][i];td2.style.textAlign = "center";

        tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);
        t_table.appendChild(tr);
    }
}


// 删除列表
function deltr1(){
    var tb = document.getElementById('t_table2');
    var rowNum=tb.rows.length;
    for (i=0;i<rowNum;i++) {
        tb.deleteRow(i);
        rowNum=rowNum-1;
        i=i-1;
    }
}



// 选择委托人
function choice_consignor(ele_id) {
     // var checked_label = document.getElementById("checked-label");
     // var span = document.createElement("span");
     // span.innerHTML = ele_id;span.style.marginLeft="1%";
     // checked_label.appendChild(span);
    check_more_one_not(ele_id);
    document.getElementById("checked-label").innerHTML = "<span style='margin-left: 1%;'>"+ele_id+"</span>";
}

// checkBox不允许多选
function check_more_one_not(ele_id) {
    var check_box_list = document.getElementsByClassName("check_box");
    for (var i=0; i<check_box_list.length; i++){
        if (String(check_box_list[i].id) !== String(ele_id)){
            document.getElementById(check_box_list[i].id).checked = false;
        }else {
            document.getElementById(check_box_list[i].id).checked = true;
        }
    }
}

// 选择执行人
function summit_val() {
    var executor = '';
    var checked_label = document.getElementById("checked-label");
    for (var j=0; j<checked_label.children.length; j++){
        executor = executor+checked_label.children[j].innerText+", ";
    }
    document.getElementById("executor").innerHTML = executor.slice(0, -2);
    document.getElementById("close-model").click();
}
